daily pastebin goal
85%
SHARE
TWEET

Untitled

a guest Nov 20th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if((*socket_handler = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
  2.     error("socket");
  3. }
  4. struct sockaddr_in socket_address;
  5. socket_address.sin_family = AF_INET;
  6. socket_address.sin_addr.s_addr = INADDR_ANY;
  7. socket_address.sin_port = htons(port);
  8. if(bind(*socket_handler, (struct sockaddr*)&socket_address, sizeof(socket_address)) == -1) {
  9.     error("bind");
  10. }
  11. if(listen(*socket_handler, 5) == -1) {
  12.     error("listen");
  13. }
  14. if (port == port_to_connect) {
  15.     return;
  16. }
  17.  
  18. // is it ok to connect that way?
  19. socket_address.sin_family = AF_INET;
  20. socket_address.sin_addr.s_addr = INADDR_ANY;
  21. socket_address.sins_port = htons(port_to_connect);
  22. if(connect(*socket_handler, (struct sockaddr*)&socket_address, sizeof(socket_address)) == -1) {
  23.     error("connect");
  24. }    am_i_pointing_to_myself = false;
RAW Paste Data
Top