Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #define PAYLOAD "Hello, World!"
- int main() {
- int sockfd;
- char *payload = PAYLOAD;
- struct sockaddr_in servaddr;
- if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- perror("Create socket failed.\n");
- exit(EXIT_FAILURE);
- }
- memset(&servaddr, 0, sizeof(servaddr));
- servaddr.sin_family = AF_INET;
- servaddr.sin_port = htons(4321);
- servaddr.sin_addr.s_addr = inet_addr("1.2.3.4");
- sendto(sockfd, (const char *)payload, strlen(payload),
- MSG_CONFIRM, (const struct sockaddr *) &servaddr,
- sizeof(servaddr));
- close(sockfd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement