Modem using post to an API! - NeoSnk - 02.03.2021 23:02
Hello guys, I want to do a test with the Dreamcast Modem. I learned about the BlueCrab ppp.h in KallistiOS, and I'm able to make the Modem Dial and also ping an IP. I'd like to know if it is possible to ping a PHP URL using the post method where I'm going to send some parameters, example:
http://www.mytext.com?name=dreamcast&age=21
I'm using this code:
#include <stdio.h>
#include <kos/dbglog.h>
#include <arch/arch.h>
#include <ppp/ppp.h>
#include <kos/net.h>
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
int main(int argc, char *argv[]) {
int i;
ppp_init();
i = ppp_modem_init("12", 1, NULL);
if(i < 0)
return 0;
ppp_set_login("dream", "cast");
i = ppp_connect();
if(i == -1) {
printf("Link establishment failed!\n");
return 0;
}
printf("Pinging the other side of the link (%d.%d.%d.%d)\n",
net_default_dev->gateway[0], net_default_dev->gateway[1],
net_default_dev->gateway[2], net_default_dev->gateway[3]);
for(i = 0; i < 10; ++i) {
net_icmp_send_echo(net_default_dev, net_default_dev->gateway, 1234, i,
NULL, 0);
thd_sleep(500);
}
printf("Pinging sylverant.net (67.222.144.120)\n");
for(i = 0; i < 10; ++i) {
uint8 addr[4] = { 67, 222, 144, 120 };
net_icmp_send_echo(net_default_dev, addr, 1234, i, NULL, 0);
thd_sleep(500);
}
ppp_shutdown();
return 0;
}
I tried to created a method: https://stackoverflow.com/questions/22077802/simple-c-example-of-doing-an-http-post-and-consuming-the-response
But I didn't get it working. Any input or directions would be welcome, thanks a lot.
RE: Modem using post to an API! - SWAT - 03.03.2021 07:43
Show execution log plz.
RE: Modem using post to an API! - megavolt85 - 03.03.2021 14:58
Код:
#include <stdio.h>
#include <kos/dbglog.h>
#include <arch/arch.h>
#include <ppp/ppp.h>
#include <kos/net.h>
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
int main(int argc, char *argv[])
{
int i,conn_rate = 0;
ppp_init();
i = ppp_modem_init("11111", 0, &conn_rate);
if(i < 0)
return 0;
ppp_set_login("dream", "dreamcast");
i = ppp_connect();
if(i < 0)
{
printf("Link establishment failed!\n");
return 0;
}
printf("Link established, rate is %d bps\n", conn_rate);
printf("Pinging the other side of the link (%d.%d.%d.%d)\n",
net_default_dev->gateway[0], net_default_dev->gateway[1],
net_default_dev->gateway[2], net_default_dev->gateway[3]);
for(i = 0; i < 10; ++i)
{
net_icmp_send_echo(net_default_dev, net_default_dev->gateway, 1234, i, NULL, 0);
thd_sleep(500);
}
printf("Pinging sylverant.net (138.197.20.130)\n");
for(i = 0; i < 10; ++i)
{
uint8 addr[4] = { 138, 197, 20, 130 };
net_icmp_send_echo(net_default_dev, addr, 1234, i, NULL, 0);
thd_sleep(500);
}
ppp_shutdown();
return 0;
}
Код:
--
KallistiOS ##version##:
Пн дек 14 04:23:24 MSK 2020
megavolt@megavolt85:/home/megavolt/dreamcast/kos
maple: active drivers:
Dreameye (Camera): Camera
Sound Input Peripheral: Microphone
PuruPuru (Vibration) Pack: JumpPack
VMU Driver: Clock, LCD, MemoryCard
Mouse Driver: Mouse
Keyboard Driver: Keyboard
Controller Driver: Controller
Lightgun: LightGun
DMA Buffer at ac0ad800
vid_set_mode: 640x480 VGA
dc-load console support enabled
maple: attached devices:
A0: Dreamcast Controller (01000000: Controller)
A1: Visual Memory (0e000000: Clock, LCD, MemoryCard)
lan_adapter: no device detected (wrong type = 0)
net_dev_init: detected 0 usable network device(s)
ppp_modem: connected at 33600 bps
ppp: entering phase Establish
lcp: Peer configure request received with opts:
peer accm: 00000000
peer magic: 6126407b
protocol compression on
addr/ctrl compression on
lcp: received configure ack
ppp: entering phase Network
ipcp: Peer configure request received with opts:
unknown option: 2 (len 6)
peer IP: 192.168.1.99
ipcp: peer sent configure nak with opts:
our IP: 192.168.1.98
DNS 1: 192.168.1.99
ipcp: Peer configure request received with opts:
peer IP: 192.168.1.99
ppp: dropping packet with bad final fcs, got: 9b0b
ppp: was for proto 8021
ppp: was 20 bytes long
ipcp: Peer configure request received with opts:
unknown option: 2 (len 6)
peer IP: 192.168.1.99
ipcp: received configure ack
ipcp: Peer configure request received with opts:
peer IP: 192.168.1.99
ppp: entering phase Network
Link established, rate is 33600 bps
Pinging the other side of the link (192.168.1.99)
16 bytes from 192.168.1.99: icmp_seq=0 ttl=64 time=88.415 ms
16 bytes from 192.168.1.99: icmp_seq=1 ttl=64 time=87.220 ms
16 bytes from 192.168.1.99: icmp_seq=2 ttl=64 time=89.613 ms
16 bytes from 192.168.1.99: icmp_seq=3 ttl=64 time=89.520 ms
16 bytes from 192.168.1.99: icmp_seq=4 ttl=64 time=88.099 ms
16 bytes from 192.168.1.99: icmp_seq=5 ttl=64 time=87.663 ms
16 bytes from 192.168.1.99: icmp_seq=6 ttl=64 time=86.339 ms
16 bytes from 192.168.1.99: icmp_seq=7 ttl=64 time=89.626 ms
16 bytes from 192.168.1.99: icmp_seq=8 ttl=64 time=88.878 ms
16 bytes from 192.168.1.99: icmp_seq=9 ttl=64 time=87.884 ms
Pinging sylverant.net (138.197.20.130)
16 bytes from 138.197.20.130: icmp_seq=0 ttl=52 time=230.623 ms
16 bytes from 138.197.20.130: icmp_seq=1 ttl=52 time=224.942 ms
16 bytes from 138.197.20.130: icmp_seq=2 ttl=52 time=222.708 ms
16 bytes from 138.197.20.130: icmp_seq=3 ttl=52 time=228.495 ms
16 bytes from 138.197.20.130: icmp_seq=4 ttl=52 time=224.635 ms
16 bytes from 138.197.20.130: icmp_seq=5 ttl=52 time=230.281 ms
16 bytes from 138.197.20.130: icmp_seq=6 ttl=52 time=240.357 ms
16 bytes from 138.197.20.130: icmp_seq=7 ttl=52 time=226.467 ms
16 bytes from 138.197.20.130: icmp_seq=8 ttl=52 time=219.864 ms
16 bytes from 138.197.20.130: icmp_seq=9 ttl=52 time=226.144 ms
arch: shutting down kernel
net_unreg_device: 'bba' isn't registered
maple: final stats -- device count = 2, vbl_cntr = 3208, dma_cntr = 3191
vid_set_mode: 640x480 VGA
use DNS for ping
Код:
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <kos/net.h>
#include <kos/dbgio.h>
#include <arch/arch.h>
#include <ppp/ppp.h>
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
int main(int argc, char *argv[])
{
int i,conn_rate = 0;
struct addrinfo *ai;
struct addrinfo hints;
int err;
ppp_init();
i = ppp_modem_init("11111", 0, &conn_rate);
if(i < 0)
return 0;
ppp_set_login("dream", "dreamcast");
i = ppp_connect();
if(i < 0)
{
printf("Link establishment failed!\n");
return 0;
}
printf("Link established, rate is %d bps\n", conn_rate);
printf("Looking up IPv4 address of sylverant.net\n");
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
if((err = getaddrinfo("sylverant.net", NULL, &hints, &ai))) {
printf("Error looking up IPv4 address information: %d\n", err);
ppp_shutdown();
return 0;
}
printf("Ping sylverant.net\n");
uint8_t addr[4];
for (i = 0; i < 4; i++)
{
addr[i] = ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr >> (i*8);
}
for(i = 0; i < 10; ++i)
{
net_icmp_send_echo(net_default_dev, addr, 1234, i, NULL, 0);
thd_sleep(500);
}
freeaddrinfo(ai);
ppp_shutdown();
return 0;
}
RE: Modem using post to an API! - NeoSnk - 03.03.2021 16:18
(03.03.2021 14:58)megavolt85 писал(а):
Код:
#include <stdio.h>
#include <kos/dbglog.h>
#include <arch/arch.h>
#include <ppp/ppp.h>
#include <kos/net.h>
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
int main(int argc, char *argv[])
{
int i,conn_rate = 0;
ppp_init();
i = ppp_modem_init("11111", 0, &conn_rate);
if(i < 0)
return 0;
ppp_set_login("dream", "dreamcast");
i = ppp_connect();
if(i < 0)
{
printf("Link establishment failed!\n");
return 0;
}
printf("Link established, rate is %d bps\n", conn_rate);
printf("Pinging the other side of the link (%d.%d.%d.%d)\n",
net_default_dev->gateway[0], net_default_dev->gateway[1],
net_default_dev->gateway[2], net_default_dev->gateway[3]);
for(i = 0; i < 10; ++i)
{
net_icmp_send_echo(net_default_dev, net_default_dev->gateway, 1234, i, NULL, 0);
thd_sleep(500);
}
printf("Pinging sylverant.net (138.197.20.130)\n");
for(i = 0; i < 10; ++i)
{
uint8 addr[4] = { 138, 197, 20, 130 };
net_icmp_send_echo(net_default_dev, addr, 1234, i, NULL, 0);
thd_sleep(500);
}
ppp_shutdown();
return 0;
}
Код:
--
KallistiOS ##version##:
Пн дек 14 04:23:24 MSK 2020
megavolt@megavolt85:/home/megavolt/dreamcast/kos
maple: active drivers:
Dreameye (Camera): Camera
Sound Input Peripheral: Microphone
PuruPuru (Vibration) Pack: JumpPack
VMU Driver: Clock, LCD, MemoryCard
Mouse Driver: Mouse
Keyboard Driver: Keyboard
Controller Driver: Controller
Lightgun: LightGun
DMA Buffer at ac0ad800
vid_set_mode: 640x480 VGA
dc-load console support enabled
maple: attached devices:
A0: Dreamcast Controller (01000000: Controller)
A1: Visual Memory (0e000000: Clock, LCD, MemoryCard)
lan_adapter: no device detected (wrong type = 0)
net_dev_init: detected 0 usable network device(s)
ppp_modem: connected at 33600 bps
ppp: entering phase Establish
lcp: Peer configure request received with opts:
peer accm: 00000000
peer magic: 6126407b
protocol compression on
addr/ctrl compression on
lcp: received configure ack
ppp: entering phase Network
ipcp: Peer configure request received with opts:
unknown option: 2 (len 6)
peer IP: 192.168.1.99
ipcp: peer sent configure nak with opts:
our IP: 192.168.1.98
DNS 1: 192.168.1.99
ipcp: Peer configure request received with opts:
peer IP: 192.168.1.99
ppp: dropping packet with bad final fcs, got: 9b0b
ppp: was for proto 8021
ppp: was 20 bytes long
ipcp: Peer configure request received with opts:
unknown option: 2 (len 6)
peer IP: 192.168.1.99
ipcp: received configure ack
ipcp: Peer configure request received with opts:
peer IP: 192.168.1.99
ppp: entering phase Network
Link established, rate is 33600 bps
Pinging the other side of the link (192.168.1.99)
16 bytes from 192.168.1.99: icmp_seq=0 ttl=64 time=88.415 ms
16 bytes from 192.168.1.99: icmp_seq=1 ttl=64 time=87.220 ms
16 bytes from 192.168.1.99: icmp_seq=2 ttl=64 time=89.613 ms
16 bytes from 192.168.1.99: icmp_seq=3 ttl=64 time=89.520 ms
16 bytes from 192.168.1.99: icmp_seq=4 ttl=64 time=88.099 ms
16 bytes from 192.168.1.99: icmp_seq=5 ttl=64 time=87.663 ms
16 bytes from 192.168.1.99: icmp_seq=6 ttl=64 time=86.339 ms
16 bytes from 192.168.1.99: icmp_seq=7 ttl=64 time=89.626 ms
16 bytes from 192.168.1.99: icmp_seq=8 ttl=64 time=88.878 ms
16 bytes from 192.168.1.99: icmp_seq=9 ttl=64 time=87.884 ms
Pinging sylverant.net (138.197.20.130)
16 bytes from 138.197.20.130: icmp_seq=0 ttl=52 time=230.623 ms
16 bytes from 138.197.20.130: icmp_seq=1 ttl=52 time=224.942 ms
16 bytes from 138.197.20.130: icmp_seq=2 ttl=52 time=222.708 ms
16 bytes from 138.197.20.130: icmp_seq=3 ttl=52 time=228.495 ms
16 bytes from 138.197.20.130: icmp_seq=4 ttl=52 time=224.635 ms
16 bytes from 138.197.20.130: icmp_seq=5 ttl=52 time=230.281 ms
16 bytes from 138.197.20.130: icmp_seq=6 ttl=52 time=240.357 ms
16 bytes from 138.197.20.130: icmp_seq=7 ttl=52 time=226.467 ms
16 bytes from 138.197.20.130: icmp_seq=8 ttl=52 time=219.864 ms
16 bytes from 138.197.20.130: icmp_seq=9 ttl=52 time=226.144 ms
arch: shutting down kernel
net_unreg_device: 'bba' isn't registered
maple: final stats -- device count = 2, vbl_cntr = 3208, dma_cntr = 3191
vid_set_mode: 640x480 VGA
use DNS for ping
Код:
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <kos/net.h>
#include <kos/dbgio.h>
#include <arch/arch.h>
#include <ppp/ppp.h>
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
int main(int argc, char *argv[])
{
int i,conn_rate = 0;
struct addrinfo *ai;
struct addrinfo hints;
int err;
ppp_init();
i = ppp_modem_init("11111", 0, &conn_rate);
if(i < 0)
return 0;
ppp_set_login("dream", "dreamcast");
i = ppp_connect();
if(i < 0)
{
printf("Link establishment failed!\n");
return 0;
}
printf("Link established, rate is %d bps\n", conn_rate);
printf("Looking up IPv4 address of sylverant.net\n");
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
if((err = getaddrinfo("sylverant.net", NULL, &hints, &ai))) {
printf("Error looking up IPv4 address information: %d\n", err);
ppp_shutdown();
return 0;
}
printf("Ping sylverant.net\n");
uint8_t addr[4];
for (i = 0; i < 4; i++)
{
addr[i] = ((struct sockaddr_in *)ai->ai_addr)->sin_addr.s_addr >> (i*8);
}
for(i = 0; i < 10; ++i)
{
net_icmp_send_echo(net_default_dev, addr, 1234, i, NULL, 0);
thd_sleep(500);
}
freeaddrinfo(ai);
ppp_shutdown();
return 0;
}
Thanks a lot Megavolt85, is it possible to ping a URL and send some parameters to a post method?
I want to make a online ranking, so the URL would receive something like:
http://www.mygame.com?name="dreamcast"&score="1000"
I'm going to try to do a post using pure C++ anyway.
(02.03.2021 23:02)NeoSnk писал(а): Hello guys, I want to do a test with the Dreamcast Modem. I learned about the BlueCrab ppp.h in KallistiOS, and I'm able to make the Modem Dial and also ping an IP. I'd like to know if it is possible to ping a PHP URL using the post method where I'm going to send some parameters, example:
http://www.mytext.com?name=dreamcast&age=21
I'm using this code:
#include <stdio.h>
#include <kos/dbglog.h>
#include <arch/arch.h>
#include <ppp/ppp.h>
#include <kos/net.h>
KOS_INIT_FLAGS(INIT_DEFAULT | INIT_NET);
int main(int argc, char *argv[]) {
int i;
ppp_init();
i = ppp_modem_init("12", 1, NULL);
if(i < 0)
return 0;
ppp_set_login("dream", "cast");
i = ppp_connect();
if(i == -1) {
printf("Link establishment failed!\n");
return 0;
}
printf("Pinging the other side of the link (%d.%d.%d.%d)\n",
net_default_dev->gateway[0], net_default_dev->gateway[1],
net_default_dev->gateway[2], net_default_dev->gateway[3]);
for(i = 0; i < 10; ++i) {
net_icmp_send_echo(net_default_dev, net_default_dev->gateway, 1234, i,
NULL, 0);
thd_sleep(500);
}
printf("Pinging sylverant.net (67.222.144.120)\n");
for(i = 0; i < 10; ++i) {
uint8 addr[4] = { 67, 222, 144, 120 };
net_icmp_send_echo(net_default_dev, addr, 1234, i, NULL, 0);
thd_sleep(500);
}
ppp_shutdown();
return 0;
}
I tried to created a method: https://stackoverflow.com/questions/22077802/simple-c-example-of-doing-an-http-post-and-consuming-the-response
But I didn't get it working. Any input or directions would be welcome, thanks a lot.
I'm going to try with the MegaVolt Code and I'll get a log. thanks.
RE: Modem using post to an API! - megavolt85 - 03.03.2021 16:47
(03.03.2021 16:18)NeoSnk писал(а): I want to make a online ranking, so the URL would receive something like:
you have webserver for test connection and look result?
RE: Modem using post to an API! - NeoSnk - 03.03.2021 17:22
(03.03.2021 16:47)megavolt85 писал(а): (03.03.2021 16:18)NeoSnk писал(а): I want to make a online ranking, so the URL would receive something like:
you have webserver for test connection and look result?
Yes I did this one for testing:
https://mcdctest.000webhostapp.com/
If you ping it with some parameters, it will show the new data.
Example:
https://mcdctest.000webhostapp.com?name="Megavolt85"&score="400"
RE: Modem using post to an API! - megavolt85 - 03.03.2021 17:27
https is not a good choice for dreamcast, use only http
EDIT, oh i'm check, http supported
RE: Modem using post to an API! - megavolt85 - 04.03.2021 02:20
I'm sorry, but the network functions via a modem in KOS do not work
work only ping
you can compile example httpd, it's don't work via modem
RE: Modem using post to an API! - NeoSnk - 04.03.2021 03:34
(04.03.2021 02:20)megavolt85 писал(а): I'm sorry, but the network functions via a modem in KOS do not work
work only ping
you can compile example httpd, it's don't work via modem
It's okay, thanks a lot for trying to help me! Do you think I can get it working with the BBA?
RE: Modem using post to an API! - SWAT - 04.03.2021 08:37
(04.03.2021 03:34)NeoSnk писал(а): (04.03.2021 02:20)megavolt85 писал(а): I'm sorry, but the network functions via a modem in KOS do not work
work only ping
you can compile example httpd, it's don't work via modem
It's okay, thanks a lot for trying to help me! Do you think I can get it working with the BBA?
Network in KOS doesn't work on BBA too )) At least on my adapter.
Moreover, it never worked and the author of this code ignores this fact.
RE: Modem using post to an API! - NeoSnk - 04.03.2021 16:08
I understand!!! That is sad =/ Well, thanks a lot you two
|