tcp and fork

M

marconi

hallo there,



Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need to
make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot





sim





































for ( ; ; ) {



if ( ((connfd=Accept(listenfd, (SA *) &cliaddr,
&clilen)) < 0)&&(myclients[2].pid=0)){

if (errno == EINTR){



continue;

}



else

err_sys("accept error");

}

else if (myclients[2].pid>0)

{

err_quit("Max client");

}

curtime = time (NULL);

loctime = localtime (&curtime);

client_date = asctime (loctime);



//Check The IP and PORT number here//

if(getpeername(connfd, (struct sockaddr *) &cliaddr,
&clilen)>=0)

{

gethostname( hname, sizeof(hname) );

p = gethostbyname( hname );



for (f = 0; p->h_addr_list[f]; ++f) {

(struct in_addr *)ip = p-
>h_addr_list[f];

user_ip = p->h_name;

myclients[max_client].ip =
inet_ntoa(cliaddr.sin_addr);

myclients[max_client].port =
ntohs(cliaddr.sin_port);

myclients[max_client].time = client_date;

myclients[max_client].start = curtime;

}

myclients[max_client].pid = getpid();

//printf("client number %d has pid %d \n", max_client, getpid());
//printf("client number %d has ip %s and port %d\n", max_client,
myclients[max_client].ip, myclients[max_client].port);

//printf("client pid number %d has pid: %d ip %s
port %d time %s duration \n", max_client,
myclients[max_client].pid,
myclients[max_client].ip, myclients[max_client]-
.port,myclients[max_client].time,myclients[max_-
client].duration);

}



pipe(pipe1);

childpid = Fork();

max_client++;

if ((childpid == 0)) { // child process //

Close(pipe1[1]); // close listening
socket //

clilen = sizeof(cliaddr); // process
the request

printf("socket is %d\n", connfd);

printf("pipe1[0] is %d and pipe1[1] is
%d\n", pipe1[0], pipe1[1]);



****This is the function where i neeed to
use pipe for

str_echo(connfd,cliaddr,clilen,childpid-
,&mycounter,pipe1[0],pipe1[1],max_clien-
t,wait_time,myclients);

}

else if (childpid >0)

{



Close(pipe1[1]); // parent
closes connected socket //

}

}

}
 
J

Joona I Palaste

marconi said:
hallo there,
Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need to
make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot

Your code depends way too much on non-standard extensions to C to be
topical here. Please ask on comp.unix.programmer instead. Thanks.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"My absolute aspect is probably..."
- Mato Valtonen
 
P

Pieter Droogendijk

hallo there,



Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need to
make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot

Off-topic in c.l.c, comp.unix.programmer.

<snip gadawfully formatted piece of offtopic source code>

Before posting to comp.unix.programmer, reformat it. It's horrible. Use
two-space indentation for example, and get rid of all the excess spaces.
 
L

LibraryUser

marconi said:
Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need
to make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot

In a large part of the global world, the fork is held in the left
hand, and the knife in the right. A majority (but definitely not
all) of USAnians reverse this, in that they put down the knife
and transfer the fork to the right hand. The piping is generally
implemented with a straw, and it is customary to tip the server.

Since the C standard has no definitions contrary to the above, my
reply is quite suitable. In other words, you are off topic, and
should look for a newsgroup that deals with your system.
comp.unix.programming and alt.gourmet come to mind.
 
K

Keith Thompson

As others have mentioned, your question is off-topic here;
the folks in comp.unix.programmer can probably help you.

Before you post there, I strongly suggest that you make sure that any
code samples you include are *exactly* the code that you've actually
compiled, preferably a complete, self-contained, short program.

I mention this because you refer to functions "Accept", "Fork", and
"Close". Unix-like systems typically do not provide these functions,
but they do provide functions "accept", "fork", and "close".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Problem with tcp server 0
Linux: using "clone3" and "waitid" 0
fork() 5
'fork' query 3
Adding adressing of IPv6 to program 1
How to use shared memory with fork() ? 5
fork() 27
Fork + Waitpid 4

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top