Author Topic: c++  (Read 7310 times)

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #30 on: August 06, 2011, 10:46:47 pm »
O.o WTF!!! 3.3 Structs: I don't understand ANY of that!!! Do I have to use that stuff just if I want to open a single port?!?! Wtf!!! What is all that?!? Please tell me I can ignore that section.

PaulBird

  • Sr. Member
  • ****
  • Posts: 485
  • Reputation: 5
  • Every problem is an opportunity in disguise
    • Google
  • Badges:
Re: c++
« Reply #31 on: August 06, 2011, 10:54:00 pm »
hahaha! those are structs my friend. dont be scared , they only nibble. they are very handy, and can even be simple so no worries. here is a tut. http://www.cprogramming.com/tutorial/lesson7.html
People Never Get The Flowers While They Can Still Smell Them

PaulBird

  • Sr. Member
  • ****
  • Posts: 485
  • Reputation: 5
  • Every problem is an opportunity in disguise
    • Google
  • Badges:
Re: c++
« Reply #32 on: August 06, 2011, 10:55:17 pm »
ALSO: notice that some of the variable types he uses u may not have seen! this is because he is including sys/types.h which contains variable types usefull for sockets :)
People Never Get The Flowers While They Can Still Smell Them

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #33 on: August 06, 2011, 11:00:37 pm »
I still don't understand **** about that section. I know what Structs are btw but what happened to a simple function like "open("127.0.0.1", "2000"); or listen("2574"); ? Does it get easier to understand later?

PaulBird

  • Sr. Member
  • ****
  • Posts: 485
  • Reputation: 5
  • Every problem is an opportunity in disguise
    • Google
  • Badges:
Re: c++
« Reply #34 on: August 06, 2011, 11:02:54 pm »
ohhh! haha sry

and yeah... he explains it later i think. i wish it was that simple.. it takes at least 2x the amout of coding as the code u just postd :P but 2x more learning experience and c++ exp u gain and 2x more controllability.
People Never Get The Flowers While They Can Still Smell Them

Don't like seeing ads? Click here to register!

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #35 on: August 06, 2011, 11:04:10 pm »
Ugh so I'm going to have to like memorize section 3.3?

PaulBird

  • Sr. Member
  • ****
  • Posts: 485
  • Reputation: 5
  • Every problem is an opportunity in disguise
    • Google
  • Badges:
Re: c++
« Reply #36 on: August 06, 2011, 11:07:26 pm »
basically :\
but... think of how much badass ud be doing it in C++!

People Never Get The Flowers While They Can Still Smell Them

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #37 on: August 06, 2011, 11:08:50 pm »
Yeah. But I'd have to still find some way of getting it to monitor the DNS traffic on port 80 to get this virus to work.

PaulBird

  • Sr. Member
  • ****
  • Posts: 485
  • Reputation: 5
  • Every problem is an opportunity in disguise
    • Google
  • Badges:
Re: c++
« Reply #38 on: August 06, 2011, 11:12:03 pm »
haha ik...


maybe u cud use a high level c++ socket wrapper haha :P wudnt be as badass, but gets the job done..
im a pureist and use sys/socket.h though.
People Never Get The Flowers While They Can Still Smell Them

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #39 on: August 06, 2011, 11:13:15 pm »
Could you show me some code of a basic server and basic client? Like as basic as you can get. I like seeing source code it REALLY helps me grasp concepts.

Don't like seeing ads? Click here to register!

PaulBird

  • Sr. Member
  • ****
  • Posts: 485
  • Reputation: 5
  • Every problem is an opportunity in disguise
    • Google
  • Badges:
Re: c++
« Reply #40 on: August 06, 2011, 11:18:29 pm »
i apologize that this is C :\
sry that its not my own, but ive been so busy with studying to test out of subjects that its hard to find time for this.
but i do understand enough to make my own. just finding the time :\ i might stay up l8 tonight and make something simple..



 /* A simple server in the internet domain using TCP
   The port number is passed as an argument */
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h> 
#include <sys/socket.h>
#include <netinet/in.h>
#include <string>

void error(const char *msg)
{
    perror(msg);
    exit(1);
}

int main(int argc, char *argv[])
{
     int sockfd, newsockfd, portno;
     string reply;
     socklen_t clilen;
     char buffer[256];
     struct sockaddr_in serv_addr, cli_addr;
     int n;
     if (argc < 2) {
         fprintf(stderr,"ERROR, no port provided\n");
         exit(1);
     }
     sockfd = socket(AF_INET, SOCK_STREAM, 0);
     if (sockfd < 0) 
        error("ERROR opening socket");
     bzero((char *) &serv_addr, sizeof(serv_addr));
     portno = atoi(argv[1]);
     serv_addr.sin_family = AF_INET;
     serv_addr.sin_addr.s_addr = INADDR_ANY;
     serv_addr.sin_port = htons(portno);
     if (bind(sockfd, (struct sockaddr *) &serv_addr,
              sizeof(serv_addr)) < 0) 
              error("ERROR on binding");
     listen(sockfd,5);
     clilen = sizeof(cli_addr);
     newsockfd = accept(sockfd, 
                 (struct sockaddr *) &cli_addr, 
                 &clilen);
     if (newsockfd < 0) 
          error("ERROR on accept");
     bzero(buffer,256);
     n = read(newsockfd,buffer,255);
     if (n < 0) error("ERROR reading from socket");
     printf("Here is the message: %s\n",buffer);
     cin >> reply;
     n = write(newsockfd,reply,18);
     if (n < 0) error("ERROR writing to socket");
     close(newsockfd);
     close(sockfd);
     return 0; 
}
People Never Get The Flowers While They Can Still Smell Them

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #41 on: August 06, 2011, 11:20:30 pm »
That's supposed to be SIMPLE?!?!

PaulBird

  • Sr. Member
  • ****
  • Posts: 485
  • Reputation: 5
  • Every problem is an opportunity in disguise
    • Google
  • Badges:
Re: c++
« Reply #42 on: August 06, 2011, 11:31:45 pm »
hahha i guess :\ ik watcha mean tho.
but the code has alot of error checking, so i guess u cud simplify it a bit
People Never Get The Flowers While They Can Still Smell Them

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #43 on: August 06, 2011, 11:37:26 pm »
Yeah I already cut out that but still goddamn!! In ruby you just include sockets, use 2-3 lines to start the server then throw it into a loop. This I can barely wrap my head around. I know once I do though I will love it since I absolutely LOVE networking. I want to know everything I can about packets, protocols, etc.

A12danrulz

  • Leader
  • Hero Member
  • *****
  • Posts: 4018
  • Reputation: 217
  • Badges:
Re: c++
« Reply #44 on: August 06, 2011, 11:40:50 pm »
Could you show me the absolute simplest server possible? Just one that opens a port and waits.