Skip to content

Instantly share code, notes, and snippets.

@woodnathan
Forked from tsujp/gist:c617db3ac405fccfa50f
Last active August 29, 2015 14:21
Show Gist options
  • Save woodnathan/8b9285ce5ec825e1ca91 to your computer and use it in GitHub Desktop.
Save woodnathan/8b9285ce5ec825e1ca91 to your computer and use it in GitHub Desktop.
#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