/*------------------------------------------- | Name:start_socketsrv_0 | Description: | Parameters: | Return Type: | Comments: | See: ---------------------------------------------*/ int start_socketsrv_0(int argc, char* argv[]){ WSADATA wsaData; clt_sock=0; if (ip_start(&wsaData)) { printf("ip_start failed!"); return -1; } hsock_event=CreateEvent(NULL,FALSE,FALSE,NULL); hthr = CreateThread( (LPSECURITY_ATTRIBUTES) NULL, 0, (LPTHREAD_START_ROUTINE) tcp_srv, NULL, 0, &thr_id); if(!hthr) return -1; return 0; }
struct packet *new_udp_packet(int address_family, enum direction_t direction, u16 udp_payload_bytes, char **error) { struct packet *packet = NULL; /* the newly-allocated result packet */ struct header *udp_header = NULL; /* the UDP header info */ /* Calculate lengths in bytes of all sections of the packet */ const int ip_option_bytes = 0; const int ip_header_bytes = (ip_header_min_len(address_family) + ip_option_bytes); const int udp_header_bytes = sizeof(struct udp); const int ip_bytes = ip_header_bytes + udp_header_bytes + udp_payload_bytes; /* Sanity-check all the various lengths */ if (ip_option_bytes & 0x3) { asprintf(error, "IP options are not padded correctly " "to ensure IP header is a multiple of 4 bytes: " "%d excess bytes", ip_option_bytes & 0x3); return NULL; } assert((udp_header_bytes & 0x3) == 0); assert((ip_header_bytes & 0x3) == 0); if (ip_bytes > MAX_UDP_DATAGRAM_BYTES) { asprintf(error, "UDP datagram too large"); return NULL; } /* Allocate and zero out a packet object of the desired size */ packet = packet_new(ip_bytes); memset(packet->buffer, 0, ip_bytes); packet->direction = direction; packet->flags = 0; packet->ecn = ECN_NONE; /* Set IP header fields */ set_packet_ip_header(packet, address_family, ip_bytes, packet->ecn, IPPROTO_UDP); udp_header = packet_append_header(packet, HEADER_UDP, sizeof(struct udp)); udp_header->total_bytes = udp_header_bytes + udp_payload_bytes; /* Find the start of UDP section of the packet */ packet->udp = (struct udp *) (ip_start(packet) + ip_header_bytes); /* Set UDP header fields */ packet->udp->src_port = htons(0); packet->udp->dst_port = htons(0); packet->udp->len = htons(udp_header_bytes + udp_payload_bytes); packet->udp->check = 0; packet->ip_bytes = ip_bytes; return packet; }