Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <inttypes.h>
- #include <netinet/in.h>
- #include <stdint.h>
- #include <string.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- int main(int argc, char *argv[]) {
- int port_num = strtol(argv[1], NULL, 10);
- char* s_addr = "127.0.0.1";
- int sock = socket(AF_INET, SOCK_DGRAM, 0);
- struct sockaddr_in addr = {
- .sin_family = AF_INET,
- .sin_addr = inet_addr(s_addr),
- .sin_port = htons(port_num)
- };
- int num_in;
- int num_out;
- while(scanf("%d", &num_in) > 0) {
- sendto(sock, &num_in, sizeof(num_in), 0, (const struct sockaddr*)&addr, sizeof(addr));
- recvfrom(sock, &num_out, sizeof(num_out), 0, NULL, NULL);
- printf("%d\n", num_out);
- }
- close(sock);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement