sender.c
int send_udp(char * host, int port, char * packet, unsigned long packet_len){
    int sock = 0;
    ssize_t r;
    struct sockaddr_in serv_addr;

    if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
        fatal("[!] Error: Could not create socket: %s\n", strerror(errno));
    }

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(port);
    inet_pton(AF_INET, host, &serv_addr.sin_addr);

    callback_pre_send(sock, packet, packet_len); // user defined callback

    // payload is larger than maximum datagram, send as multiple datagrams
    if(packet_len > 65507){
        const void * position = packet;
        unsigned long rem = packet_len;

        while(rem > 0){
            if(rem > 65507){
                r = sendto(sock,position,65507,0,(struct sockaddr *)&serv_addr,sizeof(serv_addr));
            }
            else{
                r = sendto(sock,position,rem,0,(struct sockaddr *)&serv_addr,sizeof(serv_addr));
            }

            if(r < 0){
                printf("[!] Error: in chunked sendto(): %s\n", strerror(errno));
                close(sock);
                return -1;
            }

            rem -= r;
            position += r;
        }
    }
    else{
        r = sendto(sock,packet,packet_len,0,(struct sockaddr *)&serv_addr,sizeof(serv_addr));

        if(r < 0){
            printf("[!] Error: in sendto(): %s\n", strerror(errno));
            close(sock);
            return -1;
        }
    }

    callback_post_send(sock); // user defined callback
    close(sock);
    return 0;
}
/*
 * send a char array down a
 * udp socket
*/
send a char array down a
udp socket
send a char array down a udp socket
int send_udp(char * host, int port, char * packet, unsigned long packet_len){
    int sock = 0;
    ssize_t r;
    struct sockaddr_in serv_addr;
    if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
        fatal("[!] Error: Could not create socket: %s\n", strerror(errno));
    }
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(port);
    inet_pton(AF_INET, host, &serv_addr.sin_addr);
    callback_pre_send(sock, packet, packet_len); 
    if(packet_len > 65507){
        const void * position = packet;
        unsigned long rem = packet_len;
        while(rem > 0){
            if(rem > 65507){
                r = sendto(sock,position,65507,0,(struct sockaddr *)&serv_addr,sizeof(serv_addr));
            }
            else{
                r = sendto(sock,position,rem,0,(struct sockaddr *)&serv_addr,sizeof(serv_addr));
            }
            if(r < 0){
                printf("[!] Error: in chunked sendto(): %s\n", strerror(errno));
                close(sock);
                return -1;
            }
            rem -= r;
            position += r;
        }
    }
    else{
        r = sendto(sock,packet,packet_len,0,(struct sockaddr *)&serv_addr,sizeof(serv_addr));
        if(r < 0){
            printf("[!] Error: in sendto(): %s\n", strerror(errno));
            close(sock);
            return -1;
        }
    }
    callback_post_send(sock); 
    close(sock);
    return 0;
}
int send_udp ( char * host , int port , char * packet , unsigned long packet_len ) { int sock = 0 ; ssize_t r ; struct sockaddr_in serv_addr ; if ( ( sock = socket ( AF_INET , SOCK_DGRAM , 0 ) ) < 0 ) { fatal ( " \n " , strerror ( errno ) ) ; } serv_addr . sin_family = AF_INET ; serv_addr . sin_port = htons ( port ) ; inet_pton ( AF_INET , host , & serv_addr . sin_addr ) ; callback_pre_send ( sock , packet , packet_len ) ; if ( packet_len > 65507 ) { const void * position = packet ; unsigned long rem = packet_len ; while ( rem > 0 ) { if ( rem > 65507 ) { r = sendto ( sock , position , 65507 , 0 , ( struct sockaddr * ) & serv_addr , sizeof ( serv_addr ) ) ; } else { r = sendto ( sock , position , rem , 0 , ( struct sockaddr * ) & serv_addr , sizeof ( serv_addr ) ) ; } if ( r < 0 ) { printf ( " \n " , strerror ( errno ) ) ; close ( sock ) ; return -1 ; } rem -= r ; position += r ; } } else { r = sendto ( sock , packet , packet_len , 0 , ( struct sockaddr * ) & serv_addr , sizeof ( serv_addr ) ) ; if ( r < 0 ) { printf ( " \n " , strerror ( errno ) ) ; close ( sock ) ; return -1 ; } } callback_post_send ( sock ) ; close ( sock ) ; return 0 ; }
send a char array down a
 udp socket
send a char array down a udp socket
// user defined callback // payload is larger than maximum datagram, send as multiple datagrams // user defined callback