Dear all
I have connected a GSM-Modem to my Linux system and I make a internet connection with it via pppd.
pppd is configured with the parameter "demand" so that pppd will automatically establish the Internet connection if my app likes to establish the socket connection.
In my app I have programmed a TCP socket connection to connect to a server.
First I create a socket using
sockfd = socket(AF_INET, SOCK_STREAM, 0);
and then I connect to the server using
if (connect(sockfd, &dest_addr, sizeof(dest_addr)) == -1) {

Now the problem is:
If I run Connect() for the first time when no PPP is up yet then pppd will automatically establish the internet connection as expected but the Connect() function returns -1 and does not connect to the server.
However, if i just run Connect() again it then can successfully connect to the server.
I assume that the problem could have something to do with the "demand" parameter of pppd, but I am nut sure?

And, Connect() always returns errno=22(Invalid Parameter) even when the connection could be established successfully.

I start pppd using:
exec pppd /dev/ttyS1 115200 noauth usepeerdns crtscts demand defaultroute name "xxxxxxxx" connect /config/etc/ppp/ppp-on-dialer"

Does anyone please can help me fixing this problem so that my socket connection will also work at the first time when no ppp is up?
Do I need to use other pppd parameters?

I can also send my code if required

Regards
Sektionschef