By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,133 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,133 IT Pros & Developers. It's quick & easy.

tcp and fork

P: n/a

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 //

}

}

}
--
Posted via http://dbforums.com
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
marconi <me*********@dbforums.com> scribbled the following:
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 (pa*****@cc.helsinki.fi) ---------------------------\
| 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
Nov 13 '05 #2

P: n/a
On Tue, 09 Sep 2003 01:59:04 -0400
marconi <me*********@dbforums.com> wrote:

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.

--
char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
c,k,0),x(c,k+=*s-c,s+1),*k):(x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh$%c","-34*1'.+(,03#;+,)/'///*");}
Nov 13 '05 #3

P: n/a
marconi wrote:

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.

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Nov 13 '05 #4

P: n/a
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".

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.