Skip to content

Instantly share code, notes, and snippets.

@ozuma
Created August 14, 2013 06:28
Show Gist options
  • Select an option

  • Save ozuma/6228493 to your computer and use it in GitHub Desktop.

Select an option

Save ozuma/6228493 to your computer and use it in GitHub Desktop.
Send a UDP Packet. (C Code)
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int
main()
{
int sock;
struct sockaddr_in addr;
sock = socket(AF_INET, SOCK_DGRAM, 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(50001);
addr.sin_addr.s_addr = inet_addr("192.168.184.227");
sendto(sock, "HELLO", 5, 0, (struct sockaddr *)&addr, sizeof(addr));
close(sock);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment