Ver código fonte

Almost done with packet fragmentation

MissValeska 10 anos atrás
pai
commit
2231df0ea7
1 arquivos alterados com 20 adições e 5 exclusões
  1. 20
    5
      src/inet.c

+ 20
- 5
src/inet.c Ver arquivo

@@ -552,6 +552,8 @@ int new_socket(int sock_type)
552 552
 		return -1;
553 553
 	}
554 554
 
555
+        printf("Socket FD: %i ", sockfd);
556
+        
555 557
 	return sockfd;
556 558
 }
557 559
 
@@ -1064,11 +1066,24 @@ ssize_t inet_sendto(int s, const void *msg, size_t len, int flags,
1064 1066
 			error("Packet artificially fragmented: %d", stderr);
1065 1067
                                 error("\nData Length: %u", len);
1066 1068
                                 int bytesleft = len;
1067
-                                while(bytesleft > 1024) {
1068
-                                inet_sendto(s, msg, 1024, flags, to, tolen);
1069
-                                bytesleft -= 1024;
1070
-				//err=inet_sendto(s, ((const char *)msg+(len/2)),
1071
-						//len-(len/2), flags, to, tolen);
1069
+                                int sendbuf;
1070
+                                socklen_t optlen;
1071
+                                optlen = sizeof(sendbuf);
1072
+                                int res = getsockopt(s, SOL_SOCKET, SO_SNDBUF, &sendbuf, &optlen);
1073
+                                
1074
+                                error("GetSockOpt: %i \n", res);
1075
+                                
1076
+                                while(bytesleft != 0) {
1077
+                                    if(bytesleft > 64000) {
1078
+                                        inet_sendto(s, msg, 64000, flags, to, tolen);
1079
+                                        bytesleft -= 64000;
1080
+                                        //err=inet_sendto(s, ((const char *)msg+(len/2)),
1081
+                                                 //len-(len/2), flags, to, tolen);
1082
+                                    }
1083
+                                    else    {
1084
+                                        inet_sendto(s, msg, bytesleft, flags, to, tolen);
1085
+                                        bytesleft = 0;
1086
+                                    }
1072 1087
                                 }
1073 1088
 				break;
1074 1089
 			case EFAULT:

Carregando…
Cancelar
Salvar