Advertisement
kn0tsel

Viper-01

Nov 20th, 2012
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <signal.h>
  3. #include <time.h>
  4. #include <sys/socket.h>
  5.  
  6. using namespace std;
  7.  
  8. int main (int argc, char * const argv[])
  9. {    
  10.     cout << "0k dan..\n";
  11.     cout << "Here.. We.. Go..\n";
  12.  
  13.     // int
  14.     // socket(int domain, int type, int protocol);
  15.     int nSocketID = 0;
  16.     int nDomain = PF_INET;
  17. //      PF_LOCAL        Host-internal protocols, formerly called PF_UNIX,
  18. //      PF_UNIX         Host-internal protocols, deprecated, use PF_LOCAL,
  19. //      PF_INET         Internet version 4 protocols,
  20. //      PF_ROUTE        Internal Routing protocol,
  21. //      PF_KEY          Internal key-management function,
  22. //      PF_INET6        Internet version 6 protocols,
  23. //      PF_SYSTEM       System domain,
  24. //      PF_NDRV         Raw access to network device
  25.    
  26.     int nType = SOCK_DGRAM;
  27. //      SOCK_STREAM
  28. //      SOCK_DGRAM
  29. //      SOCK_RAW
  30. //      SOCK_SEQPACKET
  31. //      SOCK_RDM
  32.        
  33.     int nProt = 0; // See /etc/protocols.. pastebin.com/#0pWTF-06
  34.    
  35.     // Now create the socket..
  36.     nSocketID = socket(nDomain, nType, nProt);
  37.    
  38.     if (nSocketID != -1)
  39.     {
  40.         cout << "Created socket with ID = " << nSocketID;
  41.        
  42.         // ssize_t
  43.         // send(int socket, const void *buffer, size_t length, int flags);
  44.         //
  45.         // ssize_t
  46.         // sendmsg(int socket, const struct msghdr *message, int flags);
  47.         //
  48.         // ssize_t
  49.         // sendto(int socket, const void *buffer, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len);
  50.         ssize_t nNrBytesSent = 0;
  51.         int nBufferSize = 1024;
  52.         wchar_t buf[nBufferSize];
  53.         int nFlags =0;
  54.        
  55.         bool bQuit = false;
  56.        
  57.         while (!bQuit)
  58.         {
  59.             nNrBytesSent = send(nSocketID, buf, sizeof(buf), nFlags);
  60.            
  61.             if (nNrBytesSent == -1)
  62.             {
  63.                 cout << "Unable to send to socket..\n";
  64.                
  65.                 bQuit = true;
  66.             }
  67.             else
  68.             {
  69.                 cout << "Sent " << nNrBytesSent << " bytes..";
  70.             }
  71.            
  72.             // Wait..
  73. //          unsigned int nSecs = 1;
  74. //          unsigned int nSleptNanoSecs = sleep(nSecs);
  75. //         
  76. //          if (nSleptNanoSecs > 0)
  77. //          {
  78. //              cout << "Slept for " << nSleptNanoSecs << " nSecs..";
  79. //          }
  80.            
  81.             const struct timespec *rqtp;
  82.             struct timespec *rmtp;
  83.             int nRes = 0;
  84.             //rqtp->tv_nsec = 1e6;
  85.             //nRes = nanosleep(rqtp, rmtp);
  86.            
  87.             const sigset_t sigmask = 0;
  88.             //nRes = sigsuspend(&sigmask); // Always returns -1..
  89.            
  90.             // Read input..
  91.         }
  92.     }
  93.        
  94.     // Goodbye..
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement