SHARE
TWEET

Untitled

a guest Jan 21st, 2020 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   #include<stdio.h> #include<unistd.h> #include<sys/socket.h> #include<sys/types.h> #include<string.h> #include<netinet/ip.h> #include<arpa/inet.h>
  2. #define SERVER_PORT 1096
  3. #define SERVER_IP_ADDRESS "127.0.0.1"
  4. void send_message(int socket_descriptor) {
  5. struct in_addr network_address; if(!inet_aton(SERVER_IP_ADDRESS,&network_address))
  6. perror("inet_aton");
  7. struct sockaddr_in server_address = { .sin_family = AF_INET,
  8. .sin_port = SERVER_PORT, .sin_addr = network_address
  9. };
  10. const char *message = "Komunikat przesłany przez sieć."; if(sendto(socket_descriptor,message,strlen(message),0,
  11. (struct sockaddr *)&server_address,sizeof(server_address))<0) perror("sendto");
  12. }
  13. int main(void) {
  14. }
  15. int socket_descriptor = socket(AF_INET, SOCK_DGRAM, 0); if(socket_descriptor<0)
  16. perror("socket"); send_message(socket_descriptor);
  17. if(close(socket_descriptor)<0) perror("close");
  18. return 0;
  19.  Lis
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top