-
-
Save woodnathan/8b9285ce5ec825e1ca91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stddef.h> | |
#include <netinet/in.h> | |
// Network Packet Struct | |
typedef struct { | |
int fd; | |
struct sockaddr_in cli_addr; | |
int length; | |
char *buffer; | |
} NET_PACKET; | |
void receive_nonce( NET_PACKET *packet ) { | |
printf( "Received nonce %s\n", packet->buffer ); | |
} | |
void receive_payload( int fd, struct sockaddr_in *cli_addr, char *buffer, int length ) { | |
NET_PACKET *packet = calloc( sizeof(NET_PACKET) + length + 1, 1); | |
if( packet == NULL ) { | |
printf( "failed.\n" ); | |
exit( EXIT_FAILURE ); | |
} | |
packet->buffer = (char *)(packet + offsetof(NET_PACKET, buffer)); | |
memcpy(packet->buffer, buffer, strlen(buffer)); | |
receive_nonce( packet ); | |
free(packet); | |
} | |
int main(int argc, char *argv[]) { | |
struct sockaddr_in cli_addr = { 0 }; | |
receive_payload(0, &cli_addr, "Hello", 6); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment