Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <signal.h>
- #include <time.h>
- #include <sys/socket.h>
- using namespace std;
- int main (int argc, char * const argv[])
- {
- cout << "0k dan..\n";
- cout << "Here.. We.. Go..\n";
- // int
- // socket(int domain, int type, int protocol);
- int nSocketID = 0;
- int nDomain = PF_INET;
- // PF_LOCAL Host-internal protocols, formerly called PF_UNIX,
- // PF_UNIX Host-internal protocols, deprecated, use PF_LOCAL,
- // PF_INET Internet version 4 protocols,
- // PF_ROUTE Internal Routing protocol,
- // PF_KEY Internal key-management function,
- // PF_INET6 Internet version 6 protocols,
- // PF_SYSTEM System domain,
- // PF_NDRV Raw access to network device
- int nType = SOCK_DGRAM;
- // SOCK_STREAM
- // SOCK_DGRAM
- // SOCK_RAW
- // SOCK_SEQPACKET
- // SOCK_RDM
- int nProt = 0; // See /etc/protocols.. pastebin.com/#0pWTF-06
- // Now create the socket..
- nSocketID = socket(nDomain, nType, nProt);
- if (nSocketID != -1)
- {
- cout << "Created socket with ID = " << nSocketID;
- // ssize_t
- // send(int socket, const void *buffer, size_t length, int flags);
- //
- // ssize_t
- // sendmsg(int socket, const struct msghdr *message, int flags);
- //
- // ssize_t
- // sendto(int socket, const void *buffer, size_t length, int flags, const struct sockaddr *dest_addr, socklen_t dest_len);
- ssize_t nNrBytesSent = 0;
- int nBufferSize = 1024;
- wchar_t buf[nBufferSize];
- int nFlags =0;
- bool bQuit = false;
- while (!bQuit)
- {
- nNrBytesSent = send(nSocketID, buf, sizeof(buf), nFlags);
- if (nNrBytesSent == -1)
- {
- cout << "Unable to send to socket..\n";
- bQuit = true;
- }
- else
- {
- cout << "Sent " << nNrBytesSent << " bytes..";
- }
- // Wait..
- // unsigned int nSecs = 1;
- // unsigned int nSleptNanoSecs = sleep(nSecs);
- //
- // if (nSleptNanoSecs > 0)
- // {
- // cout << "Slept for " << nSleptNanoSecs << " nSecs..";
- // }
- const struct timespec *rqtp;
- struct timespec *rmtp;
- int nRes = 0;
- //rqtp->tv_nsec = 1e6;
- //nRes = nanosleep(rqtp, rmtp);
- const sigset_t sigmask = 0;
- //nRes = sigsuspend(&sigmask); // Always returns -1..
- // Read input..
- }
- }
- // Goodbye..
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement